package com.hooda.utils;

import com.hooda.framework.factory.ProxyHandler;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Proxy;

/**
 * @author zhangzp
 * @version 1.0, 2021/9/10
 */
public final class ProxyUtils {

    public static Object createJdkProxy(Object target, ProxyHandler handler) {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), (o, method, args) -> handler.handle(target, method, args));
    }

    public static Object createCglibProxy(Object target, ProxyHandler handler) {
        return Enhancer.create(target.getClass(), (net.sf.cglib.proxy.MethodInterceptor) (o, method, args, methodProxy) -> handler.handle(target, method, args));
    }



}
